/*************************************************************************
	> File Name: oj-530_police_car.cpp
	> Author: Wang Bo
	> Mail: 1276106221@qq.com
	> Created Time: 2020年11月20日 星期五 20时12分48秒
 ************************************************************************/

#include <iostream>
#include <queue>
#include <string>
using namespace std;

struct node {
    int x, y;
};

int n, m, cnt;
//按上下左右顺序存方向数组
int dir[4][2] = {-1, 0, 1, 0, 0, -1, 0, 1};
char mmap[55][55];

int main() {
    queue<node> que;
    cin >> n >> m;
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            cin >> mmap[i][j];
            if (mmap[i][j] == '*') {
                que.push((node){i, j});
                //起点也能走
                //改为'.'方便后面判断
                mmap[i][j] = '.';
            }
        }
    }
    cin >> cnt;
    while (cnt--) {
        string str;
        cin >> str;
        //qsize预存这一层有多少点
        int dir_num, check[55][55] = {0}, qsize = que.size();
        if (str == "NORTH") {
            dir_num = 0;
        } else if (str == "SOUTH") {
            dir_num = 1;
        } else if (str == "WEST") {
            dir_num = 2;
        } else {
            dir_num = 3;
        }
        //每次搜一层，qsize个点
        while (qsize--) {
            node temp = que.front();
            que.pop();
            for (int i = 1; 1; ++i) {
                int x = temp.x + dir[dir_num][0] * i;
                int y = temp.y + dir[dir_num][1] * i;
                if (mmap[x][y] != '.') {
                    //如果不能走，break
                    break;
                }
                if (check[x][y] == 0) {
                    que.push((node){x, y});
                    check[x][y] = 1;
                }
            }
        }
    }
    //到这里，队列里剩余的元素就是最后一层的元素
    while (!que.empty()) {
        node temp = que.front();
        que.pop();
        mmap[temp.x][temp.y] = '*';
    }
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            cout << mmap[i][j];
        }
        cout << endl;
    }
    return 0;
}
